package cn.rkylin.oms.base.refundReasonType.utils.apprhandler.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageInfo;

import cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO;
import cn.rkylin.oms.base.refundReasonType.utils.apprhandler.ApprHandler;
import cn.rkylin.oms.warehouse.shiporder.service.IShiporderService;
import cn.rkylin.oms.warehouse.shiporder.vo.ShiporderVO;

/**
 * 类名:HasSendSkuHandler <br/>
 * 作用: 订单出库单已发货. <br/>
 * 创建时间: 2017年11月3日 下午2:40:00 <br/>
 * 
 * @author zhanghao
 * @version v1.0
 */
public class HasSendSkuHandler extends ApprHandler {
    private String ruleContent = "订单出库单(发货单)已发货；";
    
    @Autowired
    IShiporderService shipOrderService;

    /**
     * @see cn.rkylin.oms.base.refundReasonType.utils.apprhandler.ApprHandler#getRuleContent()
     */
    @Override
    protected String getRuleContent() {
        return ruleContent;
    }

    /**
     * @see cn.rkylin.oms.base.refundReasonType.utils.apprhandler.ApprHandler#isValid(cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO)
     */
    @Override
    protected boolean isValid(SysRefundVO sysRefundVO) throws Exception {
        boolean returnValue = true;
        /*
         * 如果该原因的退款单关联订单关联的订单出库单已系统发货，审核该原因的退款单失败，要给出失败原因；<br/>
         * 如果不存在关联的已系统发货订单出库单，该条规则校验通过。<br/>
         */
        ShiporderVO shiporderVO = new ShiporderVO();
        shiporderVO.setSourceId(sysRefundVO.getOrderId());
        shiporderVO.setSourceType("or");
        shiporderVO.setShiporderStatus("shiped");
        List<ShiporderVO> shipOrderList = shipOrderService.getShiporderList(shiporderVO);
        if(shipOrderList.size()>0) {
            returnValue = false;
        }
        return returnValue;
    }

    /**
     * @see cn.rkylin.oms.base.refundReasonType.utils.apprhandler.ApprHandler#getRuleCheckArray()
     */
    private int[] ruleCheckArray = { 2, 4 };

    @Override
    protected int[] getRuleCheckArray() {
        return ruleCheckArray;
    }
}
